package org.mspring.mlog.duoshuo.dao.impl;

import org.mspring.mlog.duoshuo.dao.DuoshuoSyncLogDao;
import org.mspring.mlog.duoshuo.entity.DuoshuoSyncLog;
import org.mspring.nbee.db.dao.callback.SqlQueryCallback;
import org.mspring.nbee.db.dao.impl.BaseDao;
import org.mspring.nbee.db.dao.sql.Sql;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Gao Youbo
 * @since 2015-02-19 13:02:47
 */
@Repository
public class DuoshuoSyncLogDaoImpl extends BaseDao<DuoshuoSyncLog> implements DuoshuoSyncLogDao {

    @Override
    public long findLastLogId() {
        Sql sql = new Sql("select max(log_id) lastLogId from t_duoshuo_sync_log");
        return executeQuery(sql, new SqlQueryCallback<Long>() {
            @Override
            public Long execute(ResultSet resultSet) throws SQLException {
                if (resultSet.next()) {
                    return resultSet.getLong("lastLogId");
                }
                return 0L;
            }
        });
    }
}
